package com.hkyp.ss.course.web.controller;

import com.hkyp.ss.course.apis.ReplyService;
import com.hkyp.ss.course.apis.dto.common.PageReq;
import com.hkyp.ss.course.apis.dto.common.PageResp;
import com.hkyp.ss.course.apis.dto.request.ReplyDTO;
import com.hkyp.ss.course.apis.dto.response.SecCommentVO;
import com.hkyp.ss.course.apis.utils.BeanMapper;
import com.hkyp.ss.course.web.dto.base.ResultBean;
import com.hkyp.ss.course.web.dto.request.WebReplyDTO;
import com.hkyp.ss.course.web.utils.UserSessionUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(description = "回复")
@Slf4j
@RestController
@RequestMapping(value = "/a/h/")
public class ReplyController {

    @Reference(version = "1.0")
    private ReplyService replyService;




    /**
     * 二级评论
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "获取回复列表(对评论的回复)")
    @RequestMapping(value = "/reply/list/{parentId}", method = RequestMethod.GET)
    public ResultBean<PageResp<SecCommentVO>> getSecCommentList(@PathVariable Long parentId, PageReq pageReq){

      return new ResultBean<>(replyService.selectSecondCommentList(parentId,pageReq));

    }


    /**
     * 二级评论
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "发表回复")
    @RequestMapping(value = "/api/reply", method = RequestMethod.POST)
    public ResultBean<PageResp<SecCommentVO>> addSecCommentList(@RequestBody @Valid WebReplyDTO replyDTO){
        replyDTO.setUserId(UserSessionUtils.getUserId());
        replyService.addReply(BeanMapper.map(replyDTO, ReplyDTO.class));
        return new ResultBean<>();

    }


}
